#! /bin/bash -eu
#
# Launch a docker container with ruby. Launches a shell by default

cd $(dirname $0)/..

docker_image="${DOCKER_IMAGE:=ruby}"
ruby_version="${RUBY_VERSION:-3.1}"
docker_volume_name="pdf-reader-gem-cache-${docker_image}${ruby_version}"
gemfile="${BUNDLE_GEMFILE:=/work/Gemfile}"

docker volume create ${docker_volume_name} > /dev/null

docker run \
  -v `pwd`:/work:rw \
  --mount source=${docker_volume_name},target=/usr/local/bundle  \
  -w /work \
  --entrypoint /work/auto/bundle-exec \
  --rm \
  -e BUNDLE_GEMFILE=${gemfile} \
  -i \
  -t ${docker_image}:${ruby_version} \
  "${@-bash}"
